package red.mlz.gameservice.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

    //交换机名称
    public static final String CATEGORY_EXCHANGE = "category.exchange";
    //队列名称
    public static final String CATEGORY_DELETE_GAME_QUEUE = "category.delete.game.queue";
    //路由键
    public static final String CATEGORY_DELETE_ROUTING_KEY = "category.delete.#";

    /**
     * 声明交换机
     */
    @Bean
    public TopicExchange categoryExchange() {
        return new TopicExchange(CATEGORY_EXCHANGE, true, false);
    }

    /**
     * 声明队列（持久化）
     */
    @Bean
    public Queue categoryDeleteGameQueue() {
        return new Queue(CATEGORY_DELETE_GAME_QUEUE, true, false, false);
    }

    /**
     * 绑定队列到交换机（指定路由键）
     */
    @Bean
    public Binding bindCategoryDeleteGameQueue(TopicExchange categoryExchange, Queue categoryDeleteGameQueue) {
        return BindingBuilder.bind(categoryDeleteGameQueue).to(categoryExchange).with(CATEGORY_DELETE_ROUTING_KEY);
    }
}
